/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.common.datareport.controller;

import com.icinfo.cloud.provider.punish.common.datareport.dto.CaseDataReportRequestCommonDto;
import com.icinfo.cloud.provider.punish.common.datareport.dto.CheckIsShouldReportDto;
import com.icinfo.cloud.provider.punish.common.datareport.dto.DataReportSpecialStageSpecialCaseDto;
import com.icinfo.cloud.provider.punish.common.datareport.dto.RevokeDecisionOrCaseInfoDto;
import com.icinfo.cloud.provider.punish.common.datareport.service.ICaseDataReportRecordService;
import com.icinfo.cloud.provider.punish.common.datareport.service.ICaseDataReportSecretReceiveService;
import com.icinfo.cloud.provider.punish.common.datareport.service.ICaseDataReportStageInfoService;
import com.icinfo.cloud.provider.punish.common.datareport.service.impl.*;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * 描述: 案件数据上报记录表 case_data_report_record 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年03月30日
 */
@RestController
@RefreshScope
@RequestMapping("/punish/datareport")
@Slf4j
public class CaseDataReportRecordController extends BaseController {
    @Resource
    private ICaseDataReportRecordService caseDataReportRecordService;
    @Resource
    private ICaseDataReportSecretReceiveService caseDataReportSecretReceiveService;
    @Resource
    private CaseDataReportBasicServiceImpl basicService;
    @Resource
    private CaseDataReportInvestigateServiceImpl investigateService;
    @Resource
    private CaseDataReportObtainServiceImpl obtainService;
    @Resource
    private CaseDataReportInformServiceImpl informService;
    @Resource
    private CaseDataReportHearingServiceImpl hearingService;
    @Resource
    private CaseDataReportDecisionServiceImpl decisionService;
    @Resource
    private CaseDataReportExecuteServiceImpl executeService;
    @Resource
    private CaseDataReportCloseServiceImpl closeService;
    @Resource
    private ICaseDataReportStageInfoService caseDataReportStageInfoService;

    /**
     * 描述：数据上报-base
     *
     * @param dto {@link CaseDataReportRequestCommonDto}
     * @return {@link Result<String>} 上报结果
     * @author xiangyuyu
     * @date 2022-03-30 21:23
     */
    @PostMapping("/dataReport_base")
    @ApiOperation(value = "【V1.0.0】描述：数据上报-base", httpMethod = "POST")
    public Result<String> dataReportBase(@RequestBody @Validated CaseDataReportRequestCommonDto dto) {
        return basicService.singleCaseReport(dto,null,null);
    }

    /**
     * 描述：数据上报-investigate
     *
     * @param dto {@link CaseDataReportRequestCommonDto}
     * @return {@link Result<String>} 上报结果
     * @author xiangyuyu
     * @date 2022-03-30 21:23
     */
    @PostMapping("/dataReport_investigate")
    @ApiOperation(value = "【V1.0.0】描述：数据上报-investigate", httpMethod = "POST")
    public Result<String> dataReportInvestigate(@RequestBody @Validated CaseDataReportRequestCommonDto dto) {
        return investigateService.singleCaseReport(dto,null,null);
    }

    /**
     * 描述：数据上报-obtain [目前暂不调用-无取证人相关信息]
     *
     * @param dto {@link CaseDataReportRequestCommonDto}
     * @return {@link Result<String>} 上报结果
     * @author xiangyuyu
     * @date 2022-03-30 21:23
     */
    @PostMapping("/dataReport_obtain")
    @ApiOperation(value = "【V1.0.0】描述：数据上报-obtain", httpMethod = "POST")
    public Result<String> dataReportObtain(@RequestBody @Validated CaseDataReportRequestCommonDto dto) {
        return obtainService.singleCaseReport(dto,null,null);
    }

    /**
     * 描述：数据上报-inform
     *
     * @param dto {@link CaseDataReportRequestCommonDto}
     * @return {@link Result<String>} 上报结果
     * @author xiangyuyu
     * @date 2022-03-30 21:23
     */
    @PostMapping("/dataReport_inform")
    @ApiOperation(value = "【V1.0.0】描述：数据上报-inform", httpMethod = "POST")
    public Result<String> dataReportInform(@RequestBody @Validated CaseDataReportRequestCommonDto dto) {
        return informService.singleCaseReport(dto,null,null);
    }

    /**
     * 描述：数据上报-hearing
     *
     * @param dto {@link CaseDataReportRequestCommonDto}
     * @return {@link Result<String>} 上报结果
     * @author xiangyuyu
     * @date 2022-03-30 21:23
     */
    @PostMapping("/dataReport_hearing")
    @ApiOperation(value = "【V1.0.0】描述：数据上报-hearing", httpMethod = "POST")
    public Result<String> dataReportHearing(@RequestBody @Validated CaseDataReportRequestCommonDto dto) {
        return hearingService.singleCaseReport(dto,null,null);
    }

    /**
     * 描述：数据上报-decision
     *
     * @param dto {@link CaseDataReportRequestCommonDto}
     * @return {@link Result<String>} 上报结果
     * @author xiangyuyu
     * @date 2022-03-30 21:23
     */
    @PostMapping("/dataReport_decision")
    @ApiOperation(value = "【V1.0.0】描述：数据上报-decision", httpMethod = "POST")
    public Result<String> dataReportDecision(@RequestBody @Validated CaseDataReportRequestCommonDto dto) {
        return decisionService.singleCaseReport(dto,null,null);
    }


    /**
     * 【V1.2.0】描述：处罚决定信息-撤销公示/撤案
     *
     * @param dto {@link RevokeDecisionOrCaseInfoDto}
     * @return Result<String> 上报结果
     * @author xiangyuyu
     * @date  2022/7/28
     */
    @ApiOperation(value = "【V1.2.0】描述：处罚决定信息-撤销公示/撤案", httpMethod = "POST")
    @PostMapping("/revokeDecisionOrCaseInfo")
    public Result<String> revokeDecisionOrCaseInfo(@RequestBody @Validated RevokeDecisionOrCaseInfoDto dto) {
        return decisionService.revokeDecisionOrCaseInfo(dto);
    }

    /**
     * 描述：数据上报-execute
     *
     * @param dto {@link CaseDataReportRequestCommonDto}
     * @return {@link Result<String>} 上报结果
     * @author xiangyuyu
     * @date 2022-03-30 21:23
     */
    @PostMapping("/dataReport_execute")
    @ApiOperation(value = "【V1.0.0】描述：数据上报-execute", httpMethod = "POST")
    public Result<String> dataReportExecute(@RequestBody @Validated CaseDataReportRequestCommonDto dto) {
        return executeService.singleCaseReport(dto,null,null);
    }

    /**
     * 描述：数据上报-close
     *
     * @param dto {@link CaseDataReportRequestCommonDto}
     * @return {@link Result<String>} 上报结果
     * @author xiangyuyu
     * @date 2022-03-30 21:23
     */
    @PostMapping("/dataReport_close")
    @ApiOperation(value = "【V1.0.0】描述：数据上报-close", httpMethod = "POST")
    public Result<String> dataReportClose(@RequestBody @Validated CaseDataReportRequestCommonDto dto) {
        return closeService.singleCaseReport(dto,null,null);
    }


    /**
     * 描述：获取密钥【后台测试用】
     *
     * @return String 密钥信息
     * @author xiangyuyu
     * @date 2022-04-18 09:05
     */
    @PostMapping("/getSecret")
    @ApiOperation(value = "【V1.0.0】描述：获取密钥", httpMethod = "POST")
    public String getSecret() {
        return caseDataReportSecretReceiveService.getSecret();
    }


    /**
     * 【V2.0.0】描述：基础信息-数据批量上报
     *
     * @return Result<String> 上报结果
     * @author xiangyuyu
     * @date 2022-06-13 16:02
     */
    @ApiOperation(value = "【V2.0.0】描述：基础信息-数据批量上报", httpMethod = "POST")
    @PostMapping("/basicInfoReportBatch")
    public Result<String> basicInfoReportBatch() {
        List<String> reportFailCaseIdList = basicService.batchCaseReport(null);
        return Result.success("上报失败案件id列表:【" + reportFailCaseIdList + "】");
    }

    /**
     * 【V2.0.0】描述：调查取证信息-数据批量上报
     *
     * @return Result<String> 上报结果
     * @author xiangyuyu
     * @date 2022-06-13 16:02
     */
    @ApiOperation(value = "【V2.0.0】描述：调查取证信息-数据批量上报", httpMethod = "POST")
    @PostMapping("/investigateInfoReportBatch")
    public Result<String> investigateInfoReportBatch() {
        List<String> reportFailCaseIdList = investigateService.batchCaseReport(null);
        return Result.success("上报失败案件id列表:【" + reportFailCaseIdList + "】");
    }

    /**
     * 【V2.0.0】描述：处罚告知信息-数据批量上报
     *
     * @return Result<String> 上报结果
     * @author xiangyuyu
     * @date 2022-06-13 16:02
     */
    @ApiOperation(value = "【V2.0.0】描述：处罚告知信息-数据批量上报", httpMethod = "POST")
    @PostMapping("/informInfoReportBatch")
    public Result<String> informInfoReportBatch() {
        List<String> reportFailCaseIdList = informService.batchCaseReport(null);
        return Result.success("上报失败案件id列表:【" + reportFailCaseIdList + "】");
    }

    /**
     * 【V2.0.0】描述：处罚决定信息-数据批量上报
     *
     * @return Result<String> 上报结果
     * @author xiangyuyu
     * @date 2022-06-13 16:02
     */
    @ApiOperation(value = "【V2.0.0】描述：处罚决定信息-数据批量上报", httpMethod = "POST")
    @PostMapping("/decisionInfoReportBatch")
    public Result<String> decisionInfoReportBatch() {
        List<String> reportFailCaseIdList = decisionService.batchCaseReport(null);
        return Result.success("上报失败案件id列表:【" + reportFailCaseIdList + "】");
    }

    /**
     * 【V2.0.0】描述：处罚执行信息-数据批量上报
     *
     * @return Result<String> 上报结果
     * @author xiangyuyu
     * @date 2022-06-13 16:02
     */
    @ApiOperation(value = "【V2.0.0】描述：处罚执行信息-数据批量上报", httpMethod = "POST")
    @PostMapping("/executeInfoReportBatch")
    public Result<String> executeInfoReportBatch() {
        List<String> reportFailCaseIdList = executeService.batchCaseReport(null);
        return Result.success("上报失败案件id列表:【" + reportFailCaseIdList + "】");
    }

    /**
     * 【V2.0.0】描述：结案信息-数据批量上报
     *
     * @return Result<String> 上报结果
     * @author xiangyuyu
     * @date 2022-06-13 16:02
     */
    @ApiOperation(value = "【V2.0.0】描述：结案信息-数据批量上报", httpMethod = "POST")
    @PostMapping("/closeInfoReportBatch")
    public Result<String> closeInfoReportBatch() {
        List<String> reportFailCaseIdList = closeService.batchCaseReport(null);
        return Result.success("上报失败案件id列表:【" + reportFailCaseIdList + "】");
    }

    /**
     * 描述：【V1.4.2】描述：指定阶段指定案件重新数据上报
     *
     * @param dto {@link DataReportSpecialStageSpecialCaseDto}
     * @return Result<String> 上报结果信息
     * @author xiangyuyu
     * @date 2022/9/23
     * @since 1.4.2
     */
    @ApiOperation(value = "【V1.4.2】描述：指定阶段指定案件数据上报", httpMethod = "POST")
    @PostMapping("/dataReportSpecialStageSpecialCase")
    public Result<String> dataReportSpecialStageSpecialCase(@RequestBody @Validated DataReportSpecialStageSpecialCaseDto dto) {
        return caseDataReportRecordService.dataReportSpecialStageSpecialCase(dto);
    }


    /**
     * 描述：校验是否需要上报数据
     *
     * @param dto {@link CheckIsShouldReportDto}
     * @return Result<Boolean> 是否需要数据上报
     * @author xiangyuyu
     * @date 2022/11/29
     * @since
     */
    @ApiOperation(value = "描述：校验是否需要上报数据", httpMethod = "POST")
    @PostMapping("/checkIsShouldReport")
    public Result<Boolean> checkIsShouldReport(@RequestBody @Validated CheckIsShouldReportDto dto) {
        log.info("checkIsShouldReport start... dto:{}", dto);
        String reportStageTag = dto.getReportStageTag();
        String caseId = dto.getCaseId();
        String partyId = dto.getPartyId();
        boolean flag = caseDataReportStageInfoService.checkIsShouldReport(reportStageTag, caseId, partyId);
        log.info("checkIsShouldReport end... flag:{}", flag);
        return Result.success(flag);
    }


    /**
     * 描述：根据历史上报记录参数重新上报
     *
     * @param dto {@link DataReportSpecialStageSpecialCaseDto}
     * @return Result<String> 上报结果信息
     * @author xiangyuyu
     * @date 2023/3/27
     */
    @ApiOperation(value = "根据历史上报记录参数重新上报", httpMethod = "POST")
    @PostMapping("/dataReportByHistoryReportParam")
    public Result<String> dataReportByHistoryReportParam(@RequestBody @Validated DataReportSpecialStageSpecialCaseDto dto) {
        return caseDataReportRecordService.dataReportByHistoryReportParam(dto);
    }
}